home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
hornet.scene.org
/
hornet.scene.org FTP 11-25-2012.zip
/
hornet.scene.org FTP 11-25-2012
/
code
/
effects
/
bump
/
bump.doc
< prev
next >
Wrap
Text File
|
2012-06-16
|
4KB
|
91 lines
A Fast Approach at Real-Time Phong Bump Mapping
(maybe)
by Frenzy / TeSkO
────────────────────────────────────────────────────────────────────────────
This is an idea about how to do real-time phong bump mapping. I'm not sure
if it will work or if there are any shortfalls in this approach. Please do
not flame me if this sounds absolutly wrong. It was an idea and I have yet
to implement it. I just thought I'd write it down for people to read and
maybe add some CONSTRUCTIVE advice. Of course, if you've done bump mapping
and you know that this is not the way to do it then please tell me :)
Don't tell me the slow interpolating normals method. Thats not any good
for real time! Whatever your thoughts, at least it might make you think or
at least come up with an idea of your own..
The Idea:
────────────────────────────────────────────────────────────────────────────
You firstly have two maps. One is the texture map and the other is a bump
map. They are identical except the bump map is precalculated and does
not represent pixel colour like the texture map. If you were to draw them
both on screen you'd see they look like each other but the bump map would
have weird colours :)
First thing you should do is calculate the theta values for each vertex
in the polygon. Just like in angular interpolated phong. You take the
dot product of the light vector with your vertex normals.
cos THETA = Lx*Nx + Ly*Ny + Lz*Nz
THETA = ARCCOS(cos(THETA))
Now its time to texture map. I'm assuming a linear distortional texture
mapping approach. I don't think perspective corrected texture mapping is a
good idea for this :) Interpolate your U,V coordinates like you would
normally but also interpolate those theta values like you would in
phong. Now, your ready to draw a scan line. You have, or at least should
have two things.. A set of U,V coordinates to index into the texture map
and a THETA value. This is where we start the bump mapping..
Pull out a pixel from the texture map using the U,V coordinates. Call this
pixel colour 'C'.
Next pull out a byte (not a pixel colour) from the bump map using the
same U,V coordinates. Call this value 'D'.
Now, the bytes in the bump map should be of signed magnitude.
We now add the D value to your THETA value. This displaces the theta value
by a small amount. Now, we compute the shade/intensity of that colour 'C'.
We use a lookup table structured like this:-
IntensityTable[colour][shade];
colour is the colour of the pixel you are working on, in this case 'C'.
shade is the shade of the value we want for that colour.
We also have some more work to do. We have to precalculate a table I'm
going to call this PhongIntensityTable. This will be calculated like
so:-
PhongIntensityTable[0..256]=cos(THETA)*MAXSHADES;
Still with me? Hope so..
This is what we do.. Using our displaced THETA value we calculate the
colour to plot like this:-
PixelColour = IntensityTable[C][PhongIntensityTable[THETA]]
Then we plot PixelColour where we would of ploted the original value of
'C' if we were only texture mapping.
Keep doing this until we have finished the scan line and move onto the
next. This might sound slow but its only using lookups. The only calc's
your doing is the interpolation which you would do anyway and that single
add in the loop.. All tables are pre-calculated.
Has this gave you any amazing idea's? Are you totally in agreement with
me? Are you completly bamboozled?? Whatever your thoughts please tell
me and let me share in your ideas too :)
Byeeee
Signed,
Paul aka Frenzy
EMAIL: p.adams@wlv.ac.uk